<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #someDiv{
            width: 100px;
            height: 100px;
            background: violet;
        }
    </style>
</head>
<body>
    <div id="someDiv"></div>
    <script>
        // //和setTimeout的使用一样，区别是setInterval是间隔一段时间触发一次
        // var i=0
        // setInterval(function(){
        //     i++
        //     document.write(i)
        // },1000)

        var div = document.getElementById('someDiv')
        var opacity =  1
        var fade = setInterval(function(){
            opacity -= 0.05
            div.style.opacity = opacity
            if(opacity <= 0){
                clearInterval(fade)
            }
        },30)
    </script>
</body>
</html>